<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { equipApi } from '@/api/controller';
  import { admin_id } from '@/pinia/getter';
  import { ToastSuccess, Toastloading } from '@/utils/public';
  import { ElMessageBox } from 'element-plus';
  import Pagination from "@/components/Pagination/index.vue";
  import serachUserid from '@/components/serachUserid/index.vue';
  import xmImage from '@/components/xmImage/index.vue';
  import DecisionForm from './form.vue';
  const DecisionFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page: 1,
    limit: 20,
    user_id:'',
    user_name:'',
    date:'',
  })
  const hourArr = [
    {type:1,text:'1小时'},
    {type:2,text:'永久'},
    {type:3,text:'3小时'},
  ]
  const handleOpenForm = (row:any ={},type:number = 0)=>{
    const { id, report_user_name } = row
    if(type != 1) {
      const text = type==2?'忽略':type==3?'解封':''
      ElMessageBox.confirm(`确定${text}此用户吗？`, '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        submitDecision(`${text}成功`,{
          id,type
        })
      }).catch(() => { })
    }
    if(type == 1) DecisionFormRef.value.openDialog({
      hourArr,
      id,
      type,
      nickName:report_user_name
    })
  }
  const submitDecision = async(text='',query:any = {})=>{
    const loading = Toastloading();
    const { id, type, hour } = query
    const form = {
      id,
      admin_id:admin_id.value,
      type
    } as any
    if(hour) form['hour'] = hour
    await equipApi.report_change(form)
    loading.close();
    ToastSuccess(text);
    getList();
  }
  const handleFilter = ()=>{
    action.list = []
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await equipApi.change_chat_report(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.list = data
    action.total = total
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">举报人UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">举报人昵称：</div>
          <el-input type="number" v-model="listQuery.user_name" placeholder="请输入举报人昵称"/>
        </div>
        <div class="labelItem">
          <div class="label">日期：</div>
          <el-date-picker
            v-model="listQuery.date"
            type="date"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            placeholder="选择日期时间" />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleFilter">查询</el-button>
        </div>
      </div>
    </div>
    
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column width="80" prop="id" label="ID" />
      <el-table-column width="110" prop="user_id" label="发起人ID" />
      <el-table-column width="110" prop="user_uuid" label="发起人UUID" />
      <el-table-column width="140" show-overflow-tooltip prop="user_name" label="发起人昵称" />
      <el-table-column width="110" prop="report_userid" label="被举报人ID" />
      <el-table-column width="110" prop="report_uuid" label="被举报人UUID" />
      <el-table-column width="140" show-overflow-tooltip prop="report_user_name" label="被举报人昵称" />
      <el-table-column width="200" prop="pic" label="图片">
        <template #default="scoped">
          <div class="opacity-x">
            <div v-if="scoped.row.pic.length > 0" class="flex-align max-width">
              <xmImage v-for="item in scoped.row.pic" :src="item" :list="scoped.row.pic" />
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column width="200" show-overflow-tooltip prop="desc" label="文字描述" />
      <el-table-column width="200" show-overflow-tooltip prop="sendMsg" label="消息" />
      <el-table-column width="100" prop="status" label="处理状态">
        <template #default="scoped">
          <el-tag v-if="scoped.row.status == 0">未处理</el-tag>
          <el-tag v-if="scoped.row.status == 1" type="success">已处理</el-tag>
          <el-tag v-if="scoped.row.status == 2" type="danger">已封禁</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="100" prop="hour" label="封禁时间">
        <template #default="scoped">
          {{ hourArr.find(res=> res.type == scoped.row.hour)?.text || '' }}
        </template>
      </el-table-column>
      <el-table-column width="180" fixed="right" label="操作">
        <template #default="scoped">
          <template v-if="scoped.row.status == 0">
            <el-button type="danger" @click="handleOpenForm(scoped.row,1)">封禁</el-button>
            <el-button type="warning" @click="handleOpenForm(scoped.row,2)">忽略</el-button>
          </template>
          <el-button
            v-if="scoped.row.status == 2"
            type="success"
            @click="handleOpenForm(scoped.row,3)"
            >解封
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <DecisionForm ref="DecisionFormRef" @submit="submitDecision" />
  </div>
</template>
<style lang="scss" scoped>
  :deep(.el-image) {
    width: 180px;
    height: 180px;
  }
</style>